import sys
from loguru import logger
from pathlib import Path

# 项目根目录
ROOT_PATH = Path(__file__).parent.parent.parent

# 日志文件路径
LOG_PATH = ROOT_PATH / "logs"
LOG_PATH.mkdir(exist_ok=True)

# 日志格式
LOG_FORMAT = "<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"

# 配置日志
logger.configure(
    handlers=[
        # 控制台输出
        {"sink": sys.stdout, "format": LOG_FORMAT, "level": "INFO"},
        # 文件输出
        {"sink": LOG_PATH / "app.log", "format": LOG_FORMAT, "rotation": "500 MB", "level": "INFO"},
        # 错误日志
        {"sink": LOG_PATH / "error.log", "format": LOG_FORMAT, "rotation": "500 MB", "level": "ERROR"},
    ]
)

# 导出logger
def get_logger():
    return logger 